package mis.ds.ps.model.obj;

import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import mis.ds.ps.model.iface.IDisciplinas;

import org.hibernate.proxy.HibernateProxy;

import com.felees.hbnpojogen.persistence.IPojoGenEntity;

/**
 * Object mapping for hibernate-handled table: disciplinas.
 * 
 * @author autogenerated
 */

@Entity
@Table(name = "disciplinas", catalog = "initial_timetable")
public class Disciplinas implements Cloneable, Serializable, IPojoGenEntity, IDisciplinas {

	public static final String NOME = "nome";

	/** Serial Version UID. */
	private static final long serialVersionUID = -558994948L;

	/**
	 * Use a WeakHashMap so entries will be garbage collected once all entities referring to a saved hash are garbage collected themselves.
	 */
	private static final Map<Serializable, Long> SAVED_HASHES = Collections.synchronizedMap(new WeakHashMap<Serializable, Long>());

	/** hashCode temporary storage. */
	private volatile Long hashCode;

	/** Field mapping. */
	private Integer codigo;
	/** Field mapping. */
	private Long horariosId;
	/** Field mapping. */
	private Long id = 0L; // init for hibernate bug workaround
	/** Field mapping. */
	private String nome;
	/** Field mapping. */
	private String sigla;
	/** Field mapping. */
	private Long versao;

	/**
	 * Default constructor, mainly for hibernate use.
	 */
	public Disciplinas() {
		// Default constructor
	}

	/**
	 * Constructor taking a given ID.
	 * 
	 * @param id
	 *            to set
	 */
	public Disciplinas(Long id) {
		this.id = id;
	}

	/**
	 * Return the type of this class. Useful for when dealing with proxies.
	 * 
	 * @return Defining class.
	 */
	@Transient
	public Class<?> getClassType() {
		return Disciplinas.class;
	}

	/**
	 * Return the value associated with the column: codigo.
	 * 
	 * @return A Integer object (this.codigo)
	 */
	public Integer getCodigo() {
		return this.codigo;

	}

	/**
	 * Set the value related to the column: codigo.
	 * 
	 * @param codigo
	 *            the codigo value you wish to set
	 */
	public void setCodigo(final Integer codigo) {
		this.codigo = codigo;
	}

	/**
	 * Return the value associated with the column: horariosId.
	 * 
	 * @return A Long object (this.horariosId)
	 */
	@Column(name = "horarios_id")
	public Long getHorariosId() {
		return this.horariosId;

	}

	/**
	 * Set the value related to the column: horariosId.
	 * 
	 * @param horariosId
	 *            the horariosId value you wish to set
	 */
	public void setHorariosId(final Long horariosId) {
		this.horariosId = horariosId;
	}

	/**
	 * Return the value associated with the column: id.
	 * 
	 * @return A Long object (this.id)
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id", nullable = false)
	public Long getId() {
		return this.id;

	}

	/**
	 * Set the value related to the column: id.
	 * 
	 * @param id
	 *            the id value you wish to set
	 */
	public void setId(final Long id) {
		// If we've just been persisted and hashCode has been
		// returned then make sure other entities with this
		// ID return the already returned hash code
		if ((this.id == null || this.id == 0L) && (id != null) && (this.hashCode != null)) {
			SAVED_HASHES.put(id, this.hashCode);
		}
		this.id = id;
	}

	/**
	 * Return the value associated with the column: nome.
	 * 
	 * @return A String object (this.nome)
	 */
	@Column(length = 256)
	public String getNome() {
		return this.nome;

	}

	/**
	 * Set the value related to the column: nome.
	 * 
	 * @param nome
	 *            the nome value you wish to set
	 */
	public void setNome(final String nome) {
		this.nome = nome;
	}

	/**
	 * Return the value associated with the column: sigla.
	 * 
	 * @return A String object (this.sigla)
	 */
	@Column(length = 256)
	public String getSigla() {
		return this.sigla;

	}

	/**
	 * Set the value related to the column: sigla.
	 * 
	 * @param sigla
	 *            the sigla value you wish to set
	 */
	public void setSigla(final String sigla) {
		this.sigla = sigla;
	}

	/**
	 * Return the value associated with the column: versao.
	 * 
	 * @return A Long object (this.versao)
	 */
	public Long getVersao() {
		return this.versao;

	}

	/**
	 * Set the value related to the column: versao.
	 * 
	 * @param versao
	 *            the versao value you wish to set
	 */
	public void setVersao(final Long versao) {
		this.versao = versao;
	}

	/**
	 * Deep copy.
	 * 
	 * @return cloned object
	 * @throws CloneNotSupportedException
	 *             on error
	 */
	@Override
	public Disciplinas clone() throws CloneNotSupportedException {

		final Disciplinas copy = (Disciplinas) super.clone();

		copy.setCodigo(this.getCodigo());
		copy.setHorariosId(this.getHorariosId());
		copy.setId(this.getId());
		copy.setNome(this.getNome());
		copy.setSigla(this.getSigla());
		copy.setVersao(this.getVersao());
		return copy;
	}

	/**
	 * Provides toString implementation.
	 * 
	 * @see java.lang.Object#toString()
	 * @return String representation of this class.
	 */
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();

		sb.append("codigo: " + this.getCodigo() + ", ");
		sb.append("horariosId: " + this.getHorariosId() + ", ");
		sb.append("id: " + this.getId() + ", ");
		sb.append("nome: " + this.getNome() + ", ");
		sb.append("sigla: " + this.getSigla() + ", ");
		sb.append("versao: " + this.getVersao());
		return sb.toString();
	}

	/**
	 * Equals implementation.
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 * @param aThat
	 *            Object to compare with
	 * @return true/false
	 */
	@Override
	public boolean equals(final Object aThat) {
		Object proxyThat = aThat;

		if (this == aThat) {
			return true;
		}

		if (aThat instanceof HibernateProxy) {
			// narrow down the proxy to the class we are dealing with.
			try {
				proxyThat = ((HibernateProxy) aThat).getHibernateLazyInitializer().getImplementation();
			} catch (org.hibernate.ObjectNotFoundException e) {
				return false;
			}
		}
		if (aThat == null) {
			return false;
		}

		final Disciplinas that;
		try {
			that = (Disciplinas) proxyThat;
			if (!(that.getClassType().equals(this.getClassType()))) {
				return false;
			}
		} catch (org.hibernate.ObjectNotFoundException e) {
			return false;
		} catch (ClassCastException e) {
			return false;
		}

		boolean result = true;
		result = result && (((this.getId() == null) && (that.getId() == null)) || (this.getId() != null && this.getId().equals(that.getId())));
		result = result && (((getCodigo() == null) && (that.getCodigo() == null)) || (getCodigo() != null && getCodigo().equals(that.getCodigo())));
		result = result
				&& (((getHorariosId() == null) && (that.getHorariosId() == null)) || (getHorariosId() != null && getHorariosId().equals(
						that.getHorariosId())));
		result = result && (((getNome() == null) && (that.getNome() == null)) || (getNome() != null && getNome().equals(that.getNome())));
		result = result && (((getSigla() == null) && (that.getSigla() == null)) || (getSigla() != null && getSigla().equals(that.getSigla())));
		result = result && (((getVersao() == null) && (that.getVersao() == null)) || (getVersao() != null && getVersao().equals(that.getVersao())));
		return result;
	}

	/**
	 * Calculate the hashcode.
	 * 
	 * @see java.lang.Object#hashCode()
	 * @return a calculated number
	 */
	@Override
	public int hashCode() {
		if (this.hashCode == null) {
			synchronized (this) {
				if (this.hashCode == null) {
					Long newHashCode = null;

					if (getId() != null) {
						newHashCode = SAVED_HASHES.get(getId());
					}

					if (newHashCode == null) {
						if (getId() != null && getId() != 0L) {
							newHashCode = getId();
						} else {
							newHashCode = (long) super.hashCode();

						}
					}

					this.hashCode = newHashCode;
				}
			}
		}
		return (int) (this.hashCode & 0xffffff);
	}

}
